package com.gitee.huanminabc.jcommon.reflect;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.StringJoiner;

public class ReflectPath {
    //类#属性
    public static String getField(Field field) {
        return field.getDeclaringClass().getName() + "#" + field.getName();
    }
    //类.方法
    public static String getMethod(Method method) {
        return method.getDeclaringClass().getName() + "#" + method.getName();
    }

    //类.方法#(...参数...)
    public static String getMethodParam(Method method, Parameter parameter) {
        return method.getDeclaringClass().getName() + "#" + method.getName() + "(" +
                parameter.getType().getName() + "..." + parameter.getName() +
                "...)";
    }
    //类.方法#(...参数...)
    public static String getMethodParam(String className, String methodName, Class<?>[] parameterTypes) {
        StringJoiner joiner = new StringJoiner(",",
                className + "#" + methodName + "(", ")"
        );
        if (parameterTypes != null) {
            for (Class<?> parameterType : parameterTypes) {
                joiner.add(parameterType.getName());
            }
        }

        return joiner.toString();
    }


    //类.方法#(参数1,参数2)
    public static String getMethodParamAll(Method method) {
        StringJoiner joiner = new StringJoiner(",",
                method.getDeclaringClass().getName() + "#" + method.getName() + "(", ")"
        );
        for (Parameter parameter : method.getParameters()) {
            joiner.add(parameter.getType().getName());
        }
        return joiner.toString();
    }




}
